Last Update: 2019-03-19 10:43:28
Before we start, let’s load a few libraries.
rm(list = ls())
options(warn = -1)
library(knitr)
library(ggplot2)
library(caret)
library(doParallel)
registerDoParallel(cores = (detectCores() - 1))
With our libraries loaded we can start loading our data.
Let’s read in our data. Data was downloaded on March 13 at 10:24pm.
data.2015 = read.csv("data/2015.csv")
data.2016 = read.csv("data/2016.csv")
data.2017 = read.csv("data/2017.csv")
data.2018 = read.csv("data/2018.csv")
Now, we will only deal with regular season events. So let’s remove the playoffs from our datasets.
get.regular.season = function(data) {
subset(data, isPlayoffGame == 0)
}
season.2015 = get.regular.season(data.2015)
season.2016 = get.regular.season(data.2016)
season.2017 = get.regular.season(data.2017)
season.2018 = get.regular.season(data.2018)
Here is a table of all the columns we shall keep and what we shall rename them to.
| Old Column Name | New Column Name |
|---|---|
xCordAdjusted |
x |
yCordAdjusted |
y |
shotAngleAdjusted |
angle |
shotDistance |
dist |
teamCode |
team |
shotType |
type |
shooterName |
shooter |
goalieNameForShot |
goalie |
get.helpful.data = function(data) {
data.frame(x = data$xCordAdjusted,
y = data$yCordAdjusted,
angle = data$shotAngleAdjusted,
dist = data$shotDistance,
type = data$shotType,
typeNum = as.numeric(data$shotType),
goal = data$goal,
team = data$teamCode,
shooter = data$shooterName,
goalie = data$goalieNameForShot)
}
# type:
# 1 -> empty
# 2 -> BACK
# 3 -> DEFL
# 4 -> SLAP
# 5 -> SNAP
# 6 -> TIP
# 7 -> WRAP
# 8 -> WRIST
analysis.2015 = get.helpful.data(season.2015)
analysis.2016 = get.helpful.data(season.2016)
analysis.2017 = get.helpful.data(season.2017)
analysis.2018 = get.helpful.data(season.2018)
Now, we can remove incomplete cases and create our machine learning model’s giant data set.
analysis.2015 = analysis.2015[complete.cases(analysis.2015),]
analysis.2016 = analysis.2016[complete.cases(analysis.2016),]
analysis.2017 = analysis.2017[complete.cases(analysis.2017),]
analysis.all = rbind(analysis.2017, rbind(analysis.2016, analysis.2015))
analysis.all = analysis.all[complete.cases(analysis.all),]
analysis.all = droplevels(analysis.all)
analysis.2018 = analysis.2018[complete.cases(analysis.2018),]
analysis.2018 = droplevels(analysis.2018)
Here’s what analysis.2018 looks like:
analysis.2018
Now, we need a few functions to help us select certain subsets of data. We’ll define three functions: get.team.data, get.shooter.data, get.goalie.data.
get.team.data = function(data, code) {
subset(data, team == code)
}
get.shooter.data = function(data, code) {
subset(data, shooter == code)
}
get.goalie.data = function(data, code) {
subset(data, goalie == code)
}
We can calculate a few statistics, like goal (effective) percentage for a certain shot. Let’s write a function to do that right now.
calculate.goal.percentage = function(data) {
goals = sum(data$goal == 1)
total = nrow(data)
goals / total
}
So, for example, Penguins’s goal percentage against slap shots would be calculated as follows:
penguins.2018 = get.team.data(analysis.2018, "PIT")
penguins.2018.slap = subset(penguins.2018, typeNum == 4)
penguins.2018.slap.eff = calculate.goal.percentage(penguins.2018.slap)
Their goal percentage is 0.0612245.
Here is Ovechkin’s backhand percentage:
ovechkin.2018 = get.shooter.data(analysis.2018, "Alex Ovechkin")
ovechkin.2018.back = subset(ovechkin.2018, typeNum == 2)
ovechkin.2018.back.eff = calculate.goal.percentage(ovechkin.2018.back)
His goal percentage is 0.0833333.
Now, let’s look at Carey Price’s goal percentage against wraparound shots.
price.2018 = get.goalie.data(analysis.2018, "Carey Price")
price.2018.wrap = subset(price.2018, typeNum == 7)
price.2018.wrap.eff = calculate.goal.percentage(price.2018.wrap)
His goal percentage is 0.1052632.
Using the caret package, we can build machine learning models to help us determine which shot type is best.
Let’s get started with training our control.
control = trainControl(method = "repeatedcv", number = 5, repeats = 3)
Now we will train a few different types of models. Here is a list of the models we will train:
model.nnet = train(goal ~ x + y + typeNum + dist + angle,
data = analysis.all,
method = "nnet",
trControl = control)
## # weights: 22
## initial value 77737.560248
## iter 10 value 20655.164118
## iter 20 value 18813.075704
## iter 30 value 18771.856595
## iter 40 value 18659.540051
## iter 50 value 18573.913604
## iter 60 value 18530.538848
## iter 70 value 18522.049872
## iter 80 value 18519.265512
## iter 90 value 18512.419443
## iter 100 value 18511.099883
## final value 18511.099883
## stopped after 100 iterations
model.knn = train(goal ~ x + y + typeNum + dist + angle,
data = analysis.all,
method = "knn",
trControl = control)
Now our models have been made.
Let’s test our models on the 2018 data. Here’s what the testing data looks like:
analysis.2018
Now, let’s get our predictions:
nnet.prediction = predict(model.nnet, newdata = analysis.2018, na.action = na.exclude)
knn.prediction = predict(model.knn, newdata = analysis.2018, na.action = na.exclude)
nnet.prediction.data = data.frame(analysis.2018)
nnet.prediction.data$predict = nnet.prediction
knn.prediction.data = data.frame(analysis.2018)
knn.prediction.data$predict = knn.prediction
So, our Neural Network data looks like:
nnet.prediction.data
Our K-Nearest Neighbors data looks like:
knn.prediction.data
Let us visualize how distance and the goal prediction are related.
make.knn.dist.plot = function(data, primary, secondary, team) {
name = paste(team, "Predicted Goal Probability versus Distance (KNN)", sep = " ")
plot = ggplot(data) +
geom_smooth(aes(x = dist, y = predict), method = "auto",
fill = secondary, color = primary) +
labs(title = name,
x = "Distance from Net",
y = "Probability of Scoring") +
theme_minimal()
plot
}
Here’s the same function, but for the neural network data.
make.nnet.dist.plot = function(data, primary, secondary, team) {
name = paste(team, "Predicted Goal Probability versus Distance (NNet)", sep = " ")
plot = ggplot(data) +
geom_smooth(aes(x = dist, y = predict), method = "auto",
fill = secondary, color = primary) +
labs(title = name,
x = "Distance from Net",
y = "Probability of Scoring") +
theme_minimal()
plot
}
Now let’s visualize the frequency of a shot.
make.type.freq.plot = function(data, primary, secondary, team) {
name = paste(team, "Frequency per Shot Type", seq = " ")
plot = ggplot(data) +
geom_bar(aes(x = type), stat = "count",
fill = secondary, color = primary) +
labs(title = name, x = "Shot Type", y = "Count") +
theme_minimal()
plot
}
The next graph is comparing type and goal prediction.
make.knn.type.plot = function(data, primary, secondary, team) {
name = paste(team, "Predicted Goal versus Shot Type (KNN)", seq = " ")
plot = ggplot(data) +
geom_jitter(aes(x = type, y = predict), fill = primary, color = secondary) +
labs(title = name, x = "Shot Type", y = "Probability of Scoring") +
theme_minimal()
plot
}
Here is the neural net flavor of the last function.
make.nnet.type.plot = function(data, primary, secondary, team) {
name = paste(team, "Predicted Goal versus Shot Type (NNet)", seq = " ")
plot = ggplot(data) +
geom_jitter(aes(x = type, y = predict), fill = primary, color = secondary) +
labs(title = name, x = "Shot Type", y = "Probability of Scoring") +
theme_minimal()
plot
}
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
crosby.nnet = get.shooter.data(nnet.prediction.data, "Sidney Crosby")
crosby.knn = get.shooter.data(knn.prediction.data, "Sidney Crosby")
Let’s just visualize our shots type data.
crosby.type.freq = make.type.freq.plot(crosby.nnet, "#000000", "#FCB514", "Crosby")
crosby.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
crosby.knn.dist = make.knn.dist.plot(crosby.knn, "#000000", "#FCB514", "Crosby")
crosby.knn.dist
And now with the neural network.
crosby.nnet.dist = make.nnet.dist.plot(crosby.knn, "#000000", "#FCB514", "Crosby")
crosby.nnet.dist
Now let’s look at shot type versus goal probability.
crosby.knn.type = make.knn.type.plot(crosby.knn, "#000000", "#FCB514", "Crosby")
crosby.knn.type
And now with the neural network.
crosby.nnet.type = make.nnet.type.plot(crosby.nnet, "#000000", "#FCB514", "Crosby")
crosby.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
ovechkin.nnet = get.shooter.data(nnet.prediction.data, "Alex Ovechkin")
ovechkin.knn = get.shooter.data(knn.prediction.data, "Alex Ovechkin")
Let’s just visualize our shots type data.
ovechkin.type.freq = make.type.freq.plot(ovechkin.nnet, "#041E42", "#C8102E", "Ovechkin")
ovechkin.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
ovechkin.knn.dist = make.knn.dist.plot(ovechkin.knn, "#041E42", "#C8102E", "Ovechkin")
ovechkin.knn.dist
And now with the neural network.
ovechkin.nnet.dist = make.nnet.dist.plot(ovechkin.knn, "#041E42", "#C8102E", "Ovechkin")
ovechkin.nnet.dist
Now let’s look at shot type versus goal probability.
ovechkin.knn.type = make.knn.type.plot(ovechkin.knn, "#041E42", "#C8102E", "Ovechkin")
ovechkin.knn.type
And now with the neural network.
ovechkin.nnet.type = make.nnet.type.plot(ovechkin.nnet, "#041E42", "#C8102E", "Ovechkin")
ovechkin.nnet.type
mcdavid.nnet = get.shooter.data(nnet.prediction.data, "Connor McDavid")
mcdavid.knn = get.shooter.data(knn.prediction.data, "Connor McDavid")
Let’s just visualize our shots type data.
mcdavid.type.freq = make.type.freq.plot(mcdavid.nnet, "#041E42", "#FF4C00", "McDavid")
mcdavid.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
mcdavid.knn.dist = make.knn.dist.plot(mcdavid.knn, "#041E42", "#FF4C00", "McDavid")
mcdavid.knn.dist
And now with the neural network.
mcdavid.nnet.dist = make.nnet.dist.plot(mcdavid.knn, "#041E42", "#FF4C00", "McDavid")
mcdavid.nnet.dist
Now let’s look at shot type versus goal probability.
mcdavid.knn.type = make.knn.type.plot(mcdavid.knn, "#041E42", "#FF4C00", "McDavid")
mcdavid.knn.type
And now with the neural network.
mcdavid.nnet.type = make.nnet.type.plot(mcdavid.nnet, "#041E42", "#FF4C00", "McDavid")
mcdavid.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
pettersson.nnet = get.shooter.data(nnet.prediction.data, "Elias Pettersson")
pettersson.knn = get.shooter.data(knn.prediction.data, "Elias Pettersson")
Let’s just visualize our shots type data.
pettersson.type.freq = make.type.freq.plot(pettersson.nnet, "#001F5B", "#00843D", "Pettersson")
pettersson.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
pettersson.knn.dist = make.knn.dist.plot(pettersson.knn, "#001F5B", "#00843D", "Pettersson")
pettersson.knn.dist
And now with the neural network.
pettersson.nnet.dist = make.nnet.dist.plot(pettersson.knn, "#001F5B", "#00843D", "Pettersson")
pettersson.nnet.dist
Now let’s look at shot type versus goal probability.
pettersson.knn.type = make.knn.type.plot(pettersson.knn, "#001F5B", "#00843D", "Pettersson")
pettersson.knn.type
And now with the neural network.
pettersson.nnet.type = make.nnet.type.plot(pettersson.nnet, "#001F5B", "#00843D", "Pettersson")
pettersson.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
karlsson.nnet = get.shooter.data(nnet.prediction.data, "Erik Karlsson")
karlsson.knn = get.shooter.data(knn.prediction.data, "Erik Karlsson")
Let’s just visualize our shots type data.
karlsson.type.freq = make.type.freq.plot(karlsson.nnet, "#006D75", "#EA7200", "Karlsson")
karlsson.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
karlsson.knn.dist = make.knn.dist.plot(karlsson.knn, "#006D75", "#EA7200", "Karlsson")
karlsson.knn.dist
And now with the neural network.
karlsson.nnet.dist = make.nnet.dist.plot(karlsson.knn, "#006D75", "#EA7200", "Karlsson")
karlsson.nnet.dist
Now let’s look at shot type versus goal probability.
karlsson.knn.type = make.knn.type.plot(karlsson.knn, "#006D75", "#EA7200", "Karlsson")
karlsson.knn.type
And now with the neural network.
karlsson.nnet.type = make.nnet.type.plot(karlsson.nnet, "#006D75", "#EA7200", "Karlsson")
karlsson.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
doughty.nnet = get.shooter.data(nnet.prediction.data, "Drew Doughty")
doughty.knn = get.shooter.data(knn.prediction.data, "Drew Doughty")
Let’s just visualize our shots type data.
doughty.type.freq = make.type.freq.plot(doughty.nnet, "#111111", "#A2AAAD", "Doughty")
doughty.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
doughty.knn.dist = make.knn.dist.plot(doughty.knn, "#111111", "#A2AAAD", "Doughty")
doughty.knn.dist
And now with the neural network.
doughty.nnet.dist = make.nnet.dist.plot(doughty.knn, "#111111", "#A2AAAD", "Doughty")
doughty.nnet.dist
Now let’s look at shot type versus goal probability.
doughty.knn.type = make.knn.type.plot(doughty.knn, "#111111", "#A2AAAD", "Doughty")
doughty.knn.type
And now with the neural network.
doughty.nnet.type = make.nnet.type.plot(doughty.nnet, "#111111", "#A2AAAD", "Doughty")
doughty.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
letang.nnet = get.shooter.data(nnet.prediction.data, "Kris Letang")
letang.knn = get.shooter.data(knn.prediction.data, "Kris Letang")
Let’s just visualize our shots type data.
letang.type.freq = make.type.freq.plot(letang.nnet, "#000000", "#FCB514", "Letang")
letang.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
letang.knn.dist = make.knn.dist.plot(letang.knn, "#000000", "#FCB514", "Letang")
letang.knn.dist
And now with the neural network.
letang.nnet.dist = make.nnet.dist.plot(letang.knn, "#000000", "#FCB514", "Letang")
letang.nnet.dist
Now let’s look at shot type versus goal probability.
letang.knn.type = make.knn.type.plot(letang.knn, "#000000", "#FCB514", "Letang")
letang.knn.type
And now with the neural network.
letang.nnet.type = make.nnet.type.plot(letang.nnet, "#000000", "#FCB514", "Letang")
letang.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
hedman.nnet = get.shooter.data(nnet.prediction.data, "Victor Hedman")
hedman.knn = get.shooter.data(knn.prediction.data, "Victor Hedman")
Let’s just visualize our shots type data.
hedman.type.freq = make.type.freq.plot(hedman.nnet, "#002868", "#C0C0C0", "Hedman")
hedman.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
hedman.knn.dist = make.knn.dist.plot(hedman.knn, "#002868", "#C0C0C0", "Hedman")
hedman.knn.dist
And now with the neural network.
hedman.nnet.dist = make.nnet.dist.plot(hedman.knn, "#002868", "#C0C0C0", "Hedman")
hedman.nnet.dist
Now let’s look at shot type versus goal probability.
hedman.knn.type = make.knn.type.plot(hedman.knn, "#002868", "#C0C0C0", "Hedman")
hedman.knn.type
And now with the neural network.
hedman.nnet.type = make.nnet.type.plot(hedman.nnet, "#002868", "#C0C0C0", "Hedman")
hedman.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
murray.nnet = get.goalie.data(nnet.prediction.data, "Matt Murray")
murray.knn = get.goalie.data(knn.prediction.data, "Matt Murray")
Let’s just visualize our shots type data.
murray.type.freq = make.type.freq.plot(murray.nnet, "#000000", "#FCB514", "Murray")
murray.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
murray.knn.dist = make.knn.dist.plot(murray.knn, "#000000", "#FCB514", "Murray")
murray.knn.dist
And now with the neural network.
murray.nnet.dist = make.nnet.dist.plot(murray.nnet, "#000000", "#FCB514", "Murray")
murray.nnet.dist
Now let’s look at shot type versus goal probability.
murray.knn.type = make.knn.type.plot(murray.knn, "#000000", "#FCB514", "Murray")
murray.knn.type
And now with the neural network.
murray.nnet.type = make.nnet.type.plot(murray.nnet, "#000000", "#FCB514", "Murray")
murray.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
price.nnet = get.goalie.data(nnet.prediction.data, "Carey Price")
price.knn = get.goalie.data(knn.prediction.data, "Carey Price")
Let’s just visualize our shots type data.
price.type.freq = make.type.freq.plot(price.nnet, "#AF1E2D", "#192168", "Price")
price.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
price.knn.dist = make.knn.dist.plot(price.knn, "#AF1E2D", "#192168", "Price")
price.knn.dist
And now with the neural network.
price.nnet.dist = make.nnet.dist.plot(price.nnet, "#AF1E2D", "#192168", "Price")
price.nnet.dist
Now let’s look at shot type versus goal probability.
price.knn.type = make.knn.type.plot(price.knn, "#AF1E2D", "#192168", "Price")
price.knn.type
And now with the neural network.
price.nnet.type = make.nnet.type.plot(price.nnet, "#AF1E2D", "#192168", "Price")
price.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
holtby.nnet = get.goalie.data(nnet.prediction.data, "Braden Holtby")
holtby.knn = get.goalie.data(knn.prediction.data, "Braden Holtby")
Let’s just visualize our shots type data.
holtby.type.freq = make.type.freq.plot(holtby.nnet, "#041E42", "#C8102E", "Holtby")
holtby.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
holtby.knn.dist = make.knn.dist.plot(holtby.knn, "#041E42", "#C8102E", "Holtby")
holtby.knn.dist
And now with the neural network.
holtby.nnet.dist = make.nnet.dist.plot(holtby.nnet, "#041E42", "#C8102E", "Holtby")
holtby.nnet.dist
Now let’s look at shot type versus goal probability.
holtby.knn.type = make.knn.type.plot(holtby.knn, "#041E42", "#C8102E", "Holtby")
holtby.knn.type
And now with the neural network.
holtby.nnet.type = make.nnet.type.plot(holtby.nnet, "#041E42", "#C8102E", "Holtby")
holtby.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
rask.nnet = get.goalie.data(nnet.prediction.data, "Tuukka Rask")
rask.knn = get.goalie.data(knn.prediction.data, "Tuukka Rask")
Let’s just visualize our shots type data.
rask.type.freq = make.type.freq.plot(rask.nnet, "#F74902", "#000000", "Rask")
rask.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
rask.knn.dist = make.knn.dist.plot(rask.knn, "#F74902", "#000000", "Rask")
rask.knn.dist
And now with the neural network.
rask.nnet.dist = make.nnet.dist.plot(rask.nnet, "#F74902", "#000000", "Rask")
rask.nnet.dist
Now let’s look at shot type versus goal probability.
rask.knn.type = make.knn.type.plot(rask.knn, "#F74902", "#000000", "Rask")
rask.knn.type
And now with the neural network.
rask.nnet.type = make.nnet.type.plot(rask.nnet, "#F74902", "#000000", "Rask")
rask.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
bishop.nnet = get.goalie.data(nnet.prediction.data, "Ben Bishop")
bishop.knn = get.goalie.data(knn.prediction.data, "Ben Bishop")
Let’s just visualize our shots type data.
bishop.type.freq = make.type.freq.plot(bishop.nnet, "#006847", "#8F8F8C", "Bishop")
bishop.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
bishop.knn.dist = make.knn.dist.plot(bishop.knn, "#006847", "#8F8F8C", "Bishop")
bishop.knn.dist
And now with the neural network.
bishop.nnet.dist = make.nnet.dist.plot(bishop.nnet, "#006847", "#8F8F8C", "Bishop")
bishop.nnet.dist
Now let’s look at shot type versus goal probability.
bishop.knn.type = make.knn.type.plot(bishop.knn, "#006847", "#8F8F8C", "Bishop")
bishop.knn.type
And now with the neural network.
bishop.nnet.type = make.nnet.type.plot(bishop.nnet, "#006847", "#8F8F8C", "Bishop")
bishop.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
quick.nnet = get.goalie.data(nnet.prediction.data, "Jonathan Quick")
quick.knn = get.goalie.data(knn.prediction.data, "Jonathan Quick")
Let’s just visualize our shots type data.
quick.type.freq = make.type.freq.plot(quick.nnet, "#111111", "#A2AAAD", "Quick")
quick.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
quick.knn.dist = make.knn.dist.plot(quick.knn, "#111111", "#A2AAAD", "Quick")
quick.knn.dist
And now with the neural network.
quick.nnet.dist = make.nnet.dist.plot(quick.nnet, "#111111", "#A2AAAD", "Quick")
quick.nnet.dist
Now let’s look at shot type versus goal probability.
quick.knn.type = make.knn.type.plot(quick.knn, "#111111", "#A2AAAD", "Quick")
quick.knn.type
And now with the neural network.
quick.nnet.type = make.nnet.type.plot(quick.nnet, "#111111", "#A2AAAD", "Quick")
quick.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
koskinen.nnet = get.goalie.data(nnet.prediction.data, "Mikko Koskinen")
koskinen.knn = get.goalie.data(knn.prediction.data, "Mikko Koskinen")
Let’s just visualize our shots type data.
koskinen.type.freq = make.type.freq.plot(koskinen.nnet, "#041E42", "#FF4C00", "Koskinen")
koskinen.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
koskinen.knn.dist = make.knn.dist.plot(koskinen.knn, "#041E42", "#FF4C00", "Koskinen")
koskinen.knn.dist
And now with the neural network.
koskinen.nnet.dist = make.nnet.dist.plot(koskinen.nnet, "#041E42", "#FF4C00", "Koskinen")
koskinen.nnet.dist
Now let’s look at shot type versus goal probability.
koskinen.knn.type = make.knn.type.plot(koskinen.knn, "#041E42", "#FF4C00", "Koskinen")
koskinen.knn.type
And now with the neural network.
koskinen.nnet.type = make.nnet.type.plot(koskinen.nnet, "#041E42", "#FF4C00", "Koskinen")
koskinen.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
fleury.nnet = get.goalie.data(nnet.prediction.data, "Marc-Andre Fleury")
fleury.knn = get.goalie.data(knn.prediction.data, "Marc-Andre Fleury")
Let’s just visualize our shots type data.
fleury.type.freq = make.type.freq.plot(fleury.nnet, "#B4975A", "#333F42", "Fleury")
fleury.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
fleury.knn.dist = make.knn.dist.plot(fleury.knn, "#B4975A", "#333F42", "Fleury")
fleury.knn.dist
And now with the neural network.
fleury.nnet.dist = make.nnet.dist.plot(fleury.nnet, "#B4975A", "#333F42", "Fleury")
fleury.nnet.dist
Now let’s look at shot type versus goal probability.
fleury.knn.type = make.knn.type.plot(fleury.knn, "#B4975A", "#333F42", "Fleury")
fleury.knn.type
And now with the neural network.
fleury.nnet.type = make.nnet.type.plot(fleury.nnet, "#B4975A", "#333F42", "Fleury")
fleury.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
pit.nnet = get.team.data(nnet.prediction.data, "PIT")
pit.knn = get.team.data(knn.prediction.data, "PIT")
Let’s just visualize our shots type data.
pit.type.freq = make.type.freq.plot(pit.nnet, "#000000", "#FCB514", "PIT")
pit.type.freq
Here is how the Penguins did with shots versus goal probability from the KNN model.
pit.knn.dist = make.knn.dist.plot(pit.knn, "#000000", "#FCB514", "PIT")
pit.knn.dist
And now with the neural network.
pit.nnet.dist = make.nnet.dist.plot(pit.nnet, "#000000", "#FCB514", "PIT")
pit.nnet.dist
Now let’s look at shot type versus goal probability.
pit.knn.type = make.knn.type.plot(pit.knn, "#000000", "#FCB514", "PIT")
pit.knn.type
And now with the neural network.
pit.nnet.type = make.nnet.type.plot(pit.nnet, "#000000", "#FCB514", "PIT")
pit.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
tbl.nnet = get.team.data(nnet.prediction.data, "T.B")
tbl.knn = get.team.data(knn.prediction.data, "T.B")
Let’s just visualize our shots type data.
tbl.type.freq = make.type.freq.plot(tbl.nnet, "#002868", "#AAB1BF", "T.B")
tbl.type.freq
Here is how the Lightning did with shots versus goal probability from the KNN model.
tbl.knn.dist = make.knn.dist.plot(tbl.knn, "#002868", "#AAB1BF", "T.B")
tbl.knn.dist
And now with the neural network.
tbl.nnet.dist = make.nnet.dist.plot(tbl.nnet, "#002868", "#AAB1BF", "T.B")
tbl.nnet.dist
Now let’s look at shot type versus goal probability.
tbl.knn.type = make.knn.type.plot(tbl.knn, "#002868", "#AAB1BF", "T.B")
tbl.knn.type
And now with the neural network.
tbl.nnet.type = make.nnet.type.plot(tbl.nnet, "#002868", "#AAB1BF", "T.B")
tbl.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
wsh.nnet = get.team.data(nnet.prediction.data, "WSH")
wsh.knn = get.team.data(knn.prediction.data, "WSH")
Let’s just visualize our shots type data.
wsh.type.freq = make.type.freq.plot(wsh.nnet, "#041E42", "#C8102E", "WSH")
wsh.type.freq
Here is how the Cawshals did with shots versus goal probability from the KNN model.
wsh.knn.dist = make.knn.dist.plot(wsh.knn, "#041E42", "#C8102E", "WSH")
wsh.knn.dist
And now with the neural network.
wsh.nnet.dist = make.nnet.dist.plot(wsh.nnet, "#041E42", "#C8102E", "WSH")
wsh.nnet.dist
Now let’s look at shot type versus goal probability.
wsh.knn.type = make.knn.type.plot(wsh.knn, "#041E42", "#C8102E", "WSH")
wsh.knn.type
And now with the neural network.
wsh.nnet.type = make.nnet.type.plot(wsh.nnet, "#041E42", "#C8102E", "WSH")
wsh.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
vgk.nnet = get.team.data(nnet.prediction.data, "VGK")
vgk.knn = get.team.data(knn.prediction.data, "VGK")
Let’s just visualize our shots type data.
vgk.type.freq = make.type.freq.plot(vgk.nnet, "#B4975A", "#333F42", "VGK")
vgk.type.freq
Here is how the Golden Knights did with shots versus goal probability from the KNN model.
vgk.knn.dist = make.knn.dist.plot(vgk.knn, "#B4975A", "#333F42", "VGK")
vgk.knn.dist
And now with the neural network.
vgk.nnet.dist = make.nnet.dist.plot(vgk.nnet, "#B4975A", "#333F42", "VGK")
vgk.nnet.dist
Now let’s look at shot type versus goal probability.
vgk.knn.type = make.knn.type.plot(vgk.knn, "#B4975A", "#333F42", "VGK")
vgk.knn.type
And now with the neural network.
vgk.nnet.type = make.nnet.type.plot(vgk.nnet, "#B4975A", "#333F42", "VGK")
vgk.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
col.nnet = get.team.data(nnet.prediction.data, "COL")
col.knn = get.team.data(knn.prediction.data, "COL")
Let’s just visualize our shots type data.
col.type.freq = make.type.freq.plot(col.nnet, "#6F263D", "#236192", "COL")
col.type.freq
Here is how the Avalance did with shots versus goal probability from the KNN model.
col.knn.dist = make.knn.dist.plot(col.knn, "#6F263D", "#236192", "COL")
col.knn.dist
And now with the neural network.
col.nnet.dist = make.nnet.dist.plot(col.nnet, "#6F263D", "#236192", "COL")
col.nnet.dist
Now let’s look at shot type versus goal probability.
col.knn.type = make.knn.type.plot(col.knn, "#6F263D", "#236192", "COL")
col.knn.type
And now with the neural network.
col.nnet.type = make.nnet.type.plot(col.nnet, "#6F263D", "#236192", "COL")
col.nnet.type
Let’s get our data from the Neural Network and K-Nearest Neighbors algorithms.
cgy.nnet = get.team.data(nnet.prediction.data, "CGY")
cgy.knn = get.team.data(knn.prediction.data, "CGY")
Let’s just visualize our shots type data.
cgy.type.freq = make.type.freq.plot(cgy.nnet, "#C8102E", "#F1BE48", "CGY")
cgy.type.freq
Here is how the Flames did with shots versus goal probability from the KNN model.
cgy.knn.dist = make.knn.dist.plot(cgy.knn, "#C8102E", "#F1BE48", "CGY")
cgy.knn.dist
And now with the neural network.
cgy.nnet.dist = make.nnet.dist.plot(cgy.nnet, "#C8102E", "#F1BE48", "CGY")
cgy.nnet.dist
Now let’s look at shot type versus goal probability.
cgy.knn.type = make.knn.type.plot(cgy.knn, "#C8102E", "#F1BE48", "CGY")
cgy.knn.type
And now with the neural network.
cgy.nnet.type = make.nnet.type.plot(cgy.nnet, "#C8102E", "#F1BE48", "CGY")
cgy.nnet.type